﻿Imports System.Drawing
Imports System.ComponentModel

Namespace stigzler

    Public Class MySetts

        'ini file (full including .ini ending):
        Private _iniPath As String = Nothing
        Public Property IniPath() As String
            Get
                Return _iniPath
            End Get
            Set(ByVal value As String)
                _iniPath = value
            End Set
        End Property

        'Your variables names:

        Private _GEPath As String = Nothing
        Public Property GEPath() As String
            Get
                Return _GEPath
            End Get
            Set(ByVal value As String)
                _GEPath = value
            End Set
        End Property

        Private _VerboseLog As Boolean = False
        Public Property VerboseLog() As Boolean
            Get
                Return _VerboseLog
            End Get
            Set(ByVal value As Boolean)
                _VerboseLog = value
            End Set
        End Property

        Private _ShowDebug As Boolean = False
        Public Property ShowDebug() As Boolean
            Get
                Return _ShowDebug
            End Get
            Set(ByVal value As Boolean)
                _ShowDebug = value
            End Set
        End Property

        Private _LogToDebug As Boolean = False
        Public Property LogToDebug() As Boolean
            Get
                Return _LogToDebug
            End Get
            Set(ByVal value As Boolean)
                _LogToDebug = value
            End Set
        End Property

        Private _SysDetsInLog As Boolean = False
        Public Property SysDetsInLog() As Boolean
            Get
                Return _SysDetsInLog
            End Get
            Set(ByVal value As Boolean)
                _SysDetsInLog = value
            End Set
        End Property

        Private _UnzipProg As Boolean
        Public Property UnzipProg() As Boolean
            Get
                Return _UnzipProg
            End Get
            Set(ByVal value As Boolean)
                _UnzipProg = value
            End Set
        End Property

        Private _showUnecm As Boolean
        Public Property ShowUnECM() As Boolean
            Get
                Return _showUnecm
            End Get
            Set(ByVal value As Boolean)
                _showUnecm = value
            End Set
        End Property


        Private _ZipExe As String
        Public Property ZipExe() As String
            Get
                Return _ZipExe
            End Get
            Set(ByVal value As String)
                _ZipExe = value
            End Set
        End Property

        Private _defDrive As String
        Public Property DefaultDrive() As String
            Get
                Return _defDrive
            End Get
            Set(ByVal value As String)
                _defDrive = value
            End Set
        End Property

        Private _delonce As Integer
        Public Property QLDelOnceKey() As Integer
            Get
                Return _delonce
            End Get
            Set(ByVal value As Integer)
                _delonce = value
            End Set
        End Property

        Private _delalways As Integer
        Public Property QLDelAlwaysKey() As Integer
            Get
                Return _delalways
            End Get
            Set(ByVal value As Integer)
                _delalways = value
            End Set
        End Property

        Private _keeponce As Integer
        Public Property QLKeepOnceKey() As Integer
            Get
                Return _keeponce
            End Get
            Set(ByVal value As Integer)
                _keeponce = value
            End Set
        End Property

        Private _keepalways As Integer
        Public Property QLKeepAlwaysKey() As Integer
            Get
                Return _keepalways
            End Get
            Set(ByVal value As Integer)
                _keepalways = value
            End Set
        End Property

        Private _select As Integer
        Public Property QLSelectKey() As Integer
            Get
                Return _select
            End Get
            Set(ByVal value As Integer)
                _select = value
            End Set
        End Property

        Private _msgfont As Font = New Font("Sans Serif", 10, FontStyle.Regular)
        Public Property MsgFont() As Font
            Get
                Return _msgfont
            End Get
            Set(ByVal value As Font)
                _msgfont = value
            End Set
        End Property

        Private _msgfgcol As Color = Color.Black
        Public Property MsgFGCol() As Color
            Get
                Return _msgfgcol
            End Get
            Set(ByVal value As Color)
                _msgfgcol = value
            End Set
        End Property

        Private _msgbgcol As Color = Color.LightGray
        Public Property MsgBGCol() As Color
            Get
                Return _msgbgcol
            End Get
            Set(ByVal value As Color)
                _msgbgcol = value
            End Set
        End Property


        Private _msgimg As String = Nothing
        Public Property MsgImg() As String
            Get
                Return _msgimg
            End Get
            Set(ByVal value As String)
                _msgimg = value
            End Set
        End Property

        Private _delql As Boolean
        Public Property DeleteQuicklaunch() As Boolean
            Get
                Return _delql
            End Get
            Set(ByVal value As Boolean)
                _delql = value
            End Set
        End Property

        Private _emudel As Boolean
        Public Property AllowEmuDelete() As Boolean
            Get
                Return _emudel
            End Get
            Set(ByVal value As Boolean)
                _emudel = value
            End Set
        End Property

        Private _msgticker As Boolean
        Public Property MsgTicker() As Boolean
            Get
                Return _msgticker
            End Get
            Set(ByVal value As Boolean)
                _msgticker = value
            End Set
        End Property

        Private _msgw As Integer
        Public Property MsgWidth() As Integer
            Get
                Return _msgw
            End Get
            Set(ByVal value As Integer)
                _msgw = value
            End Set
        End Property

        Private _msgh As Integer
        Public Property MsgHeight() As Integer
            Get
                Return _msgh
            End Get
            Set(ByVal value As Integer)
                _msgh = value
            End Set
        End Property

        Private _msgx As Integer
        Public Property MsgX() As Integer
            Get
                Return _msgx
            End Get
            Set(ByVal value As Integer)
                _msgx = value
            End Set
        End Property

        Private _msgy As Integer
        Public Property MsgY() As Integer
            Get
                Return _msgy
            End Get
            Set(ByVal value As Integer)
                _msgy = value
            End Set
        End Property

        Private _camnumber As Integer
        Public Property CamNumber() As Integer
            Get
                Return _camnumber
            End Get
            Set(ByVal value As Integer)
                _camnumber = value
            End Set
        End Property

        Private _cambrightness As Integer
        Public Property CamBrightness() As Integer
            Get
                Return _cambrightness
            End Get
            Set(ByVal value As Integer)
                _cambrightness = value
            End Set
        End Property

        Private _camContast As Integer
        Public Property CamContrast() As Integer
            Get
                Return _camContast
            End Get
            Set(ByVal value As Integer)
                _camContast = value
            End Set
        End Property

        Private _camgamma As Integer
        Public Property CamGamma() As Integer
            Get
                Return _camgamma
            End Get
            Set(ByVal value As Integer)
                _camgamma = value
            End Set
        End Property

        Private _camred As Integer
        Public Property CamRed() As Integer
            Get
                Return _camred
            End Get
            Set(ByVal value As Integer)
                _camred = value
            End Set
        End Property

        Private _camgreen As Integer
        Public Property CamGreen() As Integer
            Get
                Return _camgreen
            End Get
            Set(ByVal value As Integer)
                _camgreen = value
            End Set
        End Property

        Private _camblue As Integer
        Public Property CamBlue() As Integer
            Get
                Return _camblue
            End Get
            Set(ByVal value As Integer)
                _camblue = value
            End Set
        End Property

        Private _campath As String
        Public Property CamPath() As String
            Get
                Return _campath
            End Get
            Set(ByVal value As String)
                _campath = value
            End Set
        End Property

        Private _camdatefolder As Boolean
        Public Property CamDateFolder() As Boolean
            Get
                Return _camdatefolder
            End Get
            Set(ByVal value As Boolean)
                _camdatefolder = value
            End Set
        End Property

        Private _cammode As String
        Public Property CamMode() As String
            Get
                Return _cammode
            End Get
            Set(ByVal value As String)
                _cammode = value
            End Set
        End Property

        Private _camsnapgap As Integer
        Public Property CamSnapGap() As Integer
            Get
                Return _CamSnapGap
            End Get
            Set(ByVal value As Integer)
                _CamSnapGap = value
            End Set
        End Property

        Private _camburstwait As Integer
        Public Property CamBurstWait() As Integer
            Get
                Return _camburstwait
            End Get
            Set(ByVal value As Integer)
                _camburstwait = value
            End Set
        End Property

        Private _camburstnumber As Integer
        Public Property CamBurstNumber() As Integer
            Get
                Return _camburstnumber
            End Get
            Set(ByVal value As Integer)
                _camburstnumber = value
            End Set
        End Property


        Private _camsnapprob As Integer
        Public Property CamSnapProb() As Integer
            Get
                Return _camsnapprob
            End Get
            Set(ByVal value As Integer)
                _camsnapprob = value
            End Set
        End Property

        Private _camcapturefor As Integer
        Public Property CamCaptureFor() As Integer
            Get
                Return _camcapturefor
            End Get
            Set(ByVal value As Integer)
                _camcapturefor = value
            End Set
        End Property

        Private _campip As Boolean
        Public Property CamPIP() As Boolean
            Get
                Return _Campip
            End Get
            Set(ByVal value As Boolean)
                _Campip = value
            End Set
        End Property

        Private _camstamp As Boolean
        Public Property CamStamp() As Boolean
            Get
                Return _camstamp
            End Get
            Set(ByVal value As Boolean)
                _camstamp = value
            End Set
        End Property

        Private _camenabled As Boolean
        Public Property CamEnabled() As Boolean
            Get
                Return _camenabled
            End Get
            Set(ByVal value As Boolean)
                _camenabled = value
            End Set
        End Property

        Private _camhotkey As Integer
        Public Property CamHotkey() As Integer
            Get
                Return _camhotkey
            End Get
            Set(ByVal value As Integer)
                _camhotkey = value
            End Set
        End Property

        Private _camusehotkey As Boolean
        Public Property CamUseHotkey() As Boolean
            Get
                Return _camusehotkey
            End Get
            Set(ByVal value As Boolean)
                _camusehotkey = value
            End Set
        End Property

        Private _camwarn As Boolean
        Public Property CamWarn() As Boolean
            Get
                Return _camwarn
            End Get
            Set(ByVal value As Boolean)
                _camwarn = value
            End Set
        End Property

        Private _SuppSettsAudio As Boolean
        Public Property SuppSettsAudio() As Boolean
            Get
                Return _SuppSettsAudio
            End Get
            Set(ByVal value As Boolean)
                _SuppSettsAudio = value
            End Set
        End Property

        Private _GEEmuHotkey As String
        Public Property GEEmuHotkey() As String
            Get
                Return _GEEmuHotkey
            End Get
            Set(ByVal value As String)
                _GEEmuHotkey = value
            End Set
        End Property

        Private _QLGPSel As String
        Public Property QLGPSel() As String
            Get
                Return _QLGPSel
            End Get
            Set(ByVal value As String)
                _QLGPSel = value
            End Set
        End Property

        Private _camGPhotkey As String
        Public Property CamGPhotkey() As String
            Get
                Return _camGPhotkey
            End Get
            Set(ByVal value As String)
                _camGPhotkey = value
            End Set
        End Property

        Private _EmuGPhotkey As String
        Public Property EmuGPhotkey() As String
            Get
                Return _EmuGPhotkey
            End Get
            Set(ByVal value As String)
                _EmuGPhotkey = value
            End Set
        End Property

        Private _RndIntroPath As String
        Public Property RndIntroPath() As String
            Get
                Return _RndIntroPath
            End Get
            Set(ByVal value As String)
                _RndIntroPath = value
            End Set
        End Property

        Private _RndLaunchPath As String
        Public Property RndLaunchPath() As String
            Get
                Return _RndLaunchPath
            End Get
            Set(ByVal value As String)
                _RndLaunchPath = value
            End Set
        End Property

        Private _NetZipToLocal As Boolean
        Public Property NetZipToLocal() As Boolean
            Get
                Return _NetZipToLocal
            End Get
            Set(ByVal value As Boolean)
                _NetZipToLocal = value
            End Set
        End Property

        Private _dbDir As String
        Public Property DatabaseDir() As String
            Get
                Return _dbDir
            End Get
            Set(ByVal value As String)
                _dbDir = value
            End Set
        End Property

        Private _StripBrackets As Boolean
        Public Property StripBrackets() As Boolean
            Get
                Return _StripBrackets
            End Get
            Set(ByVal value As Boolean)
                _StripBrackets = value
            End Set
        End Property




        'INI FILE:
        Public Ini As New IniFile

        'Public Function InitialiseIni()
        '    Return True

        'End Function

        Public Function LoadSetts()

            Try

                If _iniPath <> Nothing Then
                    Ini.Load(_iniPath)
                    '  _GEPath = Ini.GetKeyValue("settings", "GEPath")
                    _VerboseLog = Ini.GetKeyValue("settings", "VerboseLog")
                    _ShowDebug = Ini.GetKeyValue("settings", "ShowDebug")
                    _LogToDebug = Ini.GetKeyValue("settings", "LogToDebug")
                    _SysDetsInLog = Ini.GetKeyValue("settings", "SysDetsInLog")
                    _UnzipProg = Ini.GetKeyValue("settings", "UnzipProg")
                    _ZipExe = Ini.GetKeyValue("settings", "ZipExe")
                    _showUnecm = Ini.GetKeyValue("settings", "ShowUnEcm")
                    _defDrive = Ini.GetKeyValue("settings", "DefaultDrive")
                    _delonce = Ini.GetKeyValue("Settings", "QLDelOnce")
                    _delalways = Ini.GetKeyValue("Settings", "QLDelAlways")
                    _keeponce = Ini.GetKeyValue("Settings", "QLKeepOnce")
                    _keepalways = Ini.GetKeyValue("Settings", "QLKeepAlways")
                    _select = Ini.GetKeyValue("Settings", "QLSelect")
                    _delql = Ini.GetKeyValue("Settings", "DelQL")
                    _emudel = Ini.GetKeyValue("Settings", "EmuDel")
                    _msgticker = Ini.GetKeyValue("Settings", "MsgTicker")
                    _msgw = Ini.GetKeyValue("Settings", "MsgW")
                    _msgh = Ini.GetKeyValue("Settings", "MsgH")
                    _msgx = Ini.GetKeyValue("Settings", "MsgX")
                    _msgy = Ini.GetKeyValue("Settings", "MsgY")
                    _camnumber = Ini.GetKeyValue("Settings", "CamNumber")
                    _cambrightness = Ini.GetKeyValue("Settings", "CamBrightness")
                    _camContast = Ini.GetKeyValue("Settings", "CamContrast")
                    _camgamma = Ini.GetKeyValue("Settings", "CamGamma")
                    _camred = Ini.GetKeyValue("Settings", "CamRed")
                    _camgreen = Ini.GetKeyValue("Settings", "CamGreen")
                    _camblue = Ini.GetKeyValue("Settings", "CamBlue")
                    _campath = Ini.GetKeyValue("Settings", "CamPath")
                    _camdatefolder = Ini.GetKeyValue("Settings", "CamDateFolder")
                    _cammode = Ini.GetKeyValue("Settings", "CamMode")
                    _camsnapgap = Ini.GetKeyValue("Settings", "CamSnapGap")
                    _camburstwait = Ini.GetKeyValue("Settings", "CamBurstWait")
                    _camburstnumber = Ini.GetKeyValue("Settings", "CamBurstNumber")
                    _camsnapprob = Ini.GetKeyValue("Settings", "CamSnapProb")
                    _camcapturefor = Ini.GetKeyValue("Settings", "CamCaptureFor")
                    _campip = Ini.GetKeyValue("Settings", "CamPIP")
                    _camstamp = Ini.GetKeyValue("Settings", "CamStamp")
                    _camenabled = Ini.GetKeyValue("Settings", "CamEnabled")
                    _camhotkey = Ini.GetKeyValue("Settings", "CamHotkey")
                    _camusehotkey = Ini.GetKeyValue("Settings", "CamUseHotkey")
                    _camwarn = Ini.GetKeyValue("Settings", "CamWarn")
                    _SuppSettsAudio = Ini.GetKeyValue("Settings", "SuppSettsAudio")
                    _GEEmuHotkey = Ini.GetKeyValue("Settings", "GEEmuHotkey")
                    _QLGPSel = Ini.GetKeyValue("Settings", "QLGPSel")
                    _camGPhotkey = Ini.GetKeyValue("Settings", "CamGPhotkey")
                    _EmuGPhotkey = Ini.GetKeyValue("Settings", "EmuGPhotkey")
                    _RndIntroPath = Ini.GetKeyValue("Settings", "RndIntroPath")
                    _RndLaunchPath = Ini.GetKeyValue("Settings", "RndLaunchPath")
                    _NetZipToLocal = Ini.GetKeyValue("Settings", "NetZipToLocal")
                    'NB - hereonin Use notnull to ensure compatible with older versions of the plugin (for older user ini files with added)
                    _dbDir = NotNull(Ini.GetKeyValue("Settings", "DatabaseDir"), "")
                    If Ini.GetKeyValue("Settings", "StripBrackets") = "" Then
                        _StripBrackets = True
                    Else
                        _StripBrackets = NotNull(Ini.GetKeyValue("Settings", "StripBrackets"), "True")
                    End If

                    Dim converter As TypeConverter = TypeDescriptor.GetConverter(GetType(Font))

                    ' Saving Font object as a string
                    _msgfont = DirectCast(converter.ConvertFromString(Ini.GetKeyValue("Settings", "MsgFont")), Font)

                    ' Saving Colors
                    _msgfgcol = Color.FromArgb(Ini.GetKeyValue("Settings", "MsgFGCol"))
                    _msgbgcol = Color.FromArgb(Ini.GetKeyValue("Settings", "MsgBGCol"))

                    ' Saving Image location
                    _msgimg = Ini.GetKeyValue("Settings", "MsgImg")

                    Return True
                Else
                    MsgBox("Error: No ini path passed to MySetts Class")
                    Return False
                End If

            Catch ex As Exception
                MsgBox(ex.Message & vbCr & vbCr & ex.StackTrace)
            End Try

            Return False
        End Function


        Public Function SaveSetts()
            Ini.SetKeyValue("settings", "DefaultDrive", _defDrive)
            Ini.SetKeyValue("Settings", "VerboseLog", _VerboseLog)
            Ini.SetKeyValue("Settings", "ShowDebug", _ShowDebug)
            Ini.SetKeyValue("Settings", "LogToDebug", _LogToDebug)
            Ini.SetKeyValue("Settings", "SysDetsInLog", _SysDetsInLog)
            Ini.SetKeyValue("Settings", "UnzipProg", _UnzipProg)
            Ini.SetKeyValue("Settings", "ZipExe", _ZipExe)
            Ini.SetKeyValue("Settings", "ShowUnEcm", _showUnecm)
            Ini.SetKeyValue("Settings", "QLDelOnce", _delonce)
            Ini.SetKeyValue("Settings", "QLDelAlways", _delalways)
            Ini.SetKeyValue("Settings", "QLKeepOnce", _keeponce)
            Ini.SetKeyValue("Settings", "QLKeepAlways", _keepalways)
            Ini.SetKeyValue("Settings", "QLSelect", _select)
            Ini.SetKeyValue("Settings", "DelQL", _delql)
            Ini.SetKeyValue("Settings", "EmuDel", _emudel)
            Ini.SetKeyValue("Settings", "MsgTicker", _msgticker)
            Ini.SetKeyValue("Settings", "MsgW", _msgw)
            Ini.SetKeyValue("Settings", "MsgH", _msgh)
            Ini.SetKeyValue("Settings", "MsgX", _msgx)
            Ini.SetKeyValue("Settings", "MsgY", _msgy)
            Ini.SetKeyValue("Settings", "CamNumber", _camnumber)
            Ini.SetKeyValue("Settings", "CamBrightness", _cambrightness)
            Ini.SetKeyValue("Settings", "CamContrast", _camContast)
            Ini.SetKeyValue("Settings", "CamGamma", _camgamma)
            Ini.SetKeyValue("Settings", "CamRed", _camred)
            Ini.SetKeyValue("Settings", "CamGreen", _camgreen)
            Ini.SetKeyValue("Settings", "CamBlue", _camblue)
            Ini.SetKeyValue("Settings", "CamPath", _campath)
            Ini.SetKeyValue("Settings", "CamDateFolder", _camdatefolder)
            Ini.SetKeyValue("Settings", "CamMode", _cammode)
            Ini.SetKeyValue("Settings", "CamSnapGap", _camsnapgap)
            Ini.SetKeyValue("Settings", "CamBurstWait", _camburstwait)
            Ini.SetKeyValue("Settings", "CamBurstNumber", _camburstnumber)
            Ini.SetKeyValue("Settings", "CamSnapProb", _camsnapprob)
            Ini.SetKeyValue("Settings", "CamCaptureFor", _camcapturefor)
            Ini.SetKeyValue("Settings", "CamPIP", _campip)
            Ini.SetKeyValue("Settings", "CamStamp", _camstamp)
            Ini.SetKeyValue("Settings", "CamEnabled", _camenabled)
            Ini.SetKeyValue("Settings", "CamHotkey", _camhotkey)
            Ini.SetKeyValue("Settings", "CamUseHotkey", _camusehotkey)
            Ini.SetKeyValue("Settings", "CamWarn", _camwarn)
            Ini.SetKeyValue("Settings", "SuppSettsAudio", _SuppSettsAudio)
            Ini.SetKeyValue("Settings", "GEEmuHotkey", _GEEmuHotkey)
            Ini.SetKeyValue("Settings", "QLGPSel", _QLGPSel)
            Ini.SetKeyValue("Settings", "CamGPhotkey", _camGPhotkey)
            Ini.SetKeyValue("Settings", "EmuGPhotkey", _EmuGPhotkey)
            Ini.SetKeyValue("Settings", "RndIntroPath", _RndIntroPath)
            Ini.SetKeyValue("Settings", "RndLaunchPath", _RndLaunchPath)
            Ini.SetKeyValue("Settings", "NetZipToLocal", _NetZipToLocal)
            Ini.SetKeyValue("Settings", "DatabaseDir", _dbDir)
            Ini.SetKeyValue("Settings", "StripBrackets", _StripBrackets)

            Dim converter As TypeConverter = TypeDescriptor.GetConverter(GetType(Font))
            ' Saving Font object as a string
            Dim fontString As String = converter.ConvertToString(_msgfont)
            Ini.SetKeyValue("Settings", "MsgFont", fontString)
            ' Saving Colors
            Ini.SetKeyValue("Settings", "MsgBGCol", _msgbgcol.ToArgb)
            Ini.SetKeyValue("Settings", "MsgFGCol", _msgfgcol.ToArgb)
            ' Saving Image location
            Ini.SetKeyValue("Settings", "MsgImg", _msgimg)
            Ini.Save(_iniPath)
            Return False
        End Function

        Public Shared Function NotNull(Of T)(ByVal Value As T, ByVal DefaultValue As T) As T

            If Value Is Nothing OrElse IsDBNull(Value) Then
                Return DefaultValue
            Else
                Return Value
            End If
        End Function

    End Class

End Namespace
